package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import br.com.projeto.sakila.bean.Actor;
import br.com.projeto.sakila.bean.Film;

public class ActorDao {

	private SessionFactory sessionFactory;
	private Session session;

	public ActorDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	
	public long buscarActor(){
		long tempoInicial = System.currentTimeMillis();
		
		List<Actor> listaActor = new ArrayList<>();
		try{
			session = sessionFactory.openSession(); 
			listaActor = session.createQuery("from Actor").list();
			session.close();
		} catch (Exception e){
			System.err.println("Error");
		}
		
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		
		return tempo;
	}
	
	public void listarActor(List<Actor> lista){
		System.out.println("---------------------------");
		for (Actor actor : lista) {
			System.out.println("First nome : " + actor.getFirstName());
			System.out.println("Last name : " + actor.getLastName());
			System.out.println("ID : " + actor.getId());
//			for (Film filme : actor.getFilmList()) {
//				System.out.println("//////////////////////");
//				System.out.println("FILME TITULO : " + filme.getTitle());
//				System.out.println("FILME DESCRICAO" + filme.getDescription());
//			}
			System.out.println("---------------------------");
		}
	}
	
}
